package com.example.wecomservice.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Jamin
 * @Date 2023/2/3 15:22
 */
@Configuration
public class RedissonConfig {
    private static final Log logger = LogFactory.getLog(RedissonClient.class);

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private String port;
    @Value("${spring.redis.password}")
    private String pwd;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":" + port);
        config.setCodec(new StringCodec());
        //config.useSingleServer().setUsername(name);
        if (pwd != null && !pwd.equals("")) {
            config.useSingleServer().setPassword(pwd);
        }
        logger.info("redis pwd：" + pwd);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
